package com.ruoyi.eteng.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.eteng.domain.CheckMessage;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.eteng.service.ISysCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eteng/check")
public class SysCheckController extends BaseController{

    @Autowired
    private ISysCheckService sysCheckService;


    @Autowired
    private TokenService tokenService;
    /**
     * 审核权限  1能  0 不能
     * @return
     */
    @RequestMapping("/role")
    public int checkRole(){
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        List<SysRole> roles = user.getRoles();
        if (roles.get(0).getRoleId()==6)
        {
            return 1;
        }
        return 0;
    }

    /**
     * 多选审核通过
     * @param checkMessage
     * @return
     */
    @PreAuthorize("@ss.hasPermi('eteng:check:check')")
    @PostMapping("/check")
    @Log(title = "审核通过", businessType = BusinessType.UPDATE)
    public AjaxResult check(@RequestBody CheckMessage checkMessage)
    {
        return toAjax(sysCheckService.setCheckByIds(checkMessage));
    }
}
